/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SWANLINK_FINANCE_CARDSENDER_INTERFACES_INNERKITS_NATIVE_INCLUDE_CARDSENDER_SRV_CLIENT_H
#define SWANLINK_FINANCE_CARDSENDER_INTERFACES_INNERKITS_NATIVE_INCLUDE_CARDSENDER_SRV_CLIENT_H

#include <singleton.h>
#include <memory>
#include <mutex>
#include "iremote_object.h"
#include "icardsender_srv.h"
#include <string>

namespace SwanLink {
namespace Finance {

class CardsenderSrvClient final: public OHOS::DelayedRefSingleton<CardsenderSrvClient> {
    DECLARE_DELAYED_REF_SINGLETON(CardsenderSrvClient)

 public:
    DISALLOW_COPY_AND_MOVE(CardsenderSrvClient);


    /**
     * 串口建立连接
     */
    int Open(const std::string& name, const Transport& trans);
    /**
     * 断开连接
     */
    int Close(int handle);
    /**
     * 复位发卡设备
     */
    int Reset(int handle);
    /**
     * 从卡箱发卡
     */
    int DispenseCard(int handle);
    /**
     * 获取支持的设备接入参数列表
     */
    std::vector<DevAccess> GetSupportAccess();
    /**
     * 获取设备状态。
     */
    int QueryStatus(int handle, int *suppBinStat, int *retainBinStat);

 private:
    class CardsenderSrvDeathRecipient: public OHOS::IRemoteObject::DeathRecipient {
     public:
        CardsenderSrvDeathRecipient() = default;
        ~CardsenderSrvDeathRecipient() = default;
        void OnRemoteDied(const OHOS::wptr<OHOS::IRemoteObject>& remote);
     private:
        DISALLOW_COPY_AND_MOVE(CardsenderSrvDeathRecipient);
    };

    OHOS::ErrCode Connect();
    OHOS::sptr<ICardsenderSrv> proxy_{ nullptr };
    OHOS::sptr<OHOS::IRemoteObject::DeathRecipient> deathRecipient_{ nullptr };
    void ResetProxy(const OHOS::wptr<OHOS::IRemoteObject>& remote);
    std::mutex mutex_;
};
}  // namespace Finance
}  // namespace SwanLink

#endif  // SWANLINK_FINANCE_CARDSENDER_INTERFACES_INNERKITS_NATIVE_INCLUDE_CARDSENDER_SRV_CLIENT_H
